//bange_base.hpp
//Copyright (C) 2010-2011 Oscar (.teri) Triano

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _bange_base_
#define _bange_base_

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <lua5.1/lua.hpp>

using namespace std;

namespace bange{
	
	class base{
		public:
			virtual bool NewIndex(lua_State *) = 0;
			virtual bool Index(lua_State *) = 0;
			virtual void CleanVM(lua_State *){};//Some derivated classes doesn't have defined CleanVM
			virtual std::string ToString(){
				char tostring[128] = {0};
				snprintf(tostring, 128, "bange::base: %p", this);
				return std::string(tostring);}
			virtual ~base(){};
			
			static bange::base *GetBaseFromProxy(int, lua_State *);
			static void RegisterVM(lua_State *);
	};
	
	struct baseproxy{
		int refparent;
		bange::base *base;
	};

	void BuildProxy(int, bange::base *, lua_State *);//+1, -0
	
}

static int bangebaseproxy_newindex(lua_State *);
static int bangebaseproxy_index(lua_State *);
static int bangebaseproxy_tostring(lua_State *);
static int bangebaseproxy_gc(lua_State *);

#endif
